package com.lsu.app.mapper;

import com.lsu.app.bean.Course;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

/**
 *
 * @description 针对表【course(课程)】的数据库操作Mapper
 * @Date 2023-10-18 20:26:04
 * @author hjj
 */
@Mapper
public interface CourseMapper extends BaseMapper<Course> {
    @Select("select `name` from user where id=(select teacher_id from course where id = #{id})")
    String getTeacherNameByCourseId(Integer id);//根据课程id获取教师昵称
    @Select("select COUNT(*) from course where course_name=#{name} and teacher_id = #{id}")
    Integer existCourseByName(@Param("name") String name, @Param("id") Integer id);
    @Select("select course_name from course where id=#{id}")
    String getCourseNameById(Integer id);
    @Update("update course set course_progress = course_progress+ #{amount} where id =#{id}")
    void updateCourseProgress(@Param("id")Integer id,@Param("amount")Integer amount);
    @Select("select `name` from user where id=#{id} and state=1")
    String getTeacherNameByTeacherId(Integer id);//获取教师昵称
    @Update("update course set click_num = click_num+1 where id = #{id}")
    void addClickById(Integer id);//点击量+1
    @Update("update course set click_num = click_num+#{count} where id = #{id}")
    void addClickByIdOf(@Param("id") Integer id,@Param("count") Integer count);

    @Update("update course set heat = heat +#{amount} where id = #{id}")
    void updateHeatById(@Param("id") Integer id,@Param("amount") Integer amount);//热度
    @Select("select teacher_id from course where id =#{id}")
    Integer getTeacherIdByCourseId(Integer id);//根据课程id获取教师id
    @Select("select value from kv_code where type=3 and `name`=#{kindName}")
    Integer getKindNameValueByKindName(String KindName);//获取类型id
    @Select("select id from course where teacher_id=#{teacherId}")
    List<Integer> getCourseIdsOfTeacherId(Integer teacherId);//获取教师下的所有课程id
    @Select("select id from course")
    List<Integer> getCourseIds();
    @Select("select COUNT(*) from kind where kv_value_id in (${kindIds})")
    Integer test(@Param("kindIds") String kinds);//测试 in 语法
    @Select("select count(*) from course where teacher_id=#{teacherId}")
    Integer CountCourseNumByTeacherId(Integer teacherId);//获取教师课程数
    @Select("select SUM(click_num) from course where teacher_id=#{teacherId}")
    Integer CountClickByTeacherId(Integer teacherId);//获取教师所有课程的总点击量
    @Select("select * from course where teacher_id=#{teacherId}")
    List<Course> getCourseByTeacherId(Integer teacherId); //根据教师id获取课程

}




